package io.bsly.modules.app.service.localmaster.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.bsly.common.utils.PageUtils;
import io.bsly.common.utils.Query;
import io.bsly.modules.app.dao.localDao.DyHotelProductDao;
import io.bsly.modules.app.entity.localEntity.DyHotelProductEntity;
import io.bsly.modules.app.entity.sourceEntity.HotelEntity;
import io.bsly.modules.app.pojo.HotelProductFrom;
import io.bsly.modules.app.service.localmaster.DyHotelProductService;
import io.bsly.modules.app.service.sourceDb.HotelService;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.One;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("dyHotelProductService")
public class DyHotelProductServiceImpl extends ServiceImpl<DyHotelProductDao, DyHotelProductEntity> implements DyHotelProductService {

    @Autowired
    HotelService hotelService;

    @Override
    public PageUtils queryPage(HotelProductFrom vo) {
        IPage<DyHotelProductEntity> page = this.page(
                new Page<>(vo.getPage(),vo.getLimit()),
                new QueryWrapper<DyHotelProductEntity>().lambda()
                        .eq(ObjectUtil.isNotNull(vo.getHotelId()),DyHotelProductEntity::getHotelId,vo.getHotelId())
                        .eq(ObjectUtil.isNotNull(vo.getProductId()),DyHotelProductEntity::getProductId,vo.getProductId())
                        .like(StringUtils.isNotBlank(vo.getHotelName()),DyHotelProductEntity::getName,vo.getHotelName())
                        .like(StringUtils.isNotBlank(vo.getHotelAddr()),DyHotelProductEntity::getAddress,vo.getHotelAddr())
                        .like(StringUtils.isNotBlank(vo.getCity()),DyHotelProductEntity::getCity,vo.getCity())
                .orderByDesc(DyHotelProductEntity::getId)
        );
        return new PageUtils(page);
    }
}